package com.runner.unlocks;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.runner.observer.Event;
import com.runner.observer.Subject;
import com.runner.utility.Constants;
import com.runner.utility.Locator;

public class Track1Unlock implements Constants {

	private ImageButton button;
	private Subject subject;
	private Label name;
	private Stage stage;

	public Track1Unlock(Stage stage, LabelStyle style, Subject subject) {
		this.subject = subject;
		this.stage = stage;
		createButton(style);
	}

	public void createButton(LabelStyle style) {
		Image i = new Image(Locator.getAssets().get(TRACK1_PICTURE, Texture.class));
		button = new ImageButton(i.getDrawable());
		button.addListener(new ClickListener() {
			@Override
			public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
				subject.notify(Event.EVENT_TRACK1_SELECTED);
				return false;
			}
		});
		button.setPosition(ACTUAL_VIRTUAL_WIDTH * (TRACK_X), ACTUAL_VIRTUAL_HEIGHT * (TRACK_Y+ HEIGHT_ADJUST));
		button.getImage().setScale(1 );
		button.setScale(1 );
		stage.addActor(button);

		name = new Label("Ringer Track 1", style);
		name.setPosition(ACTUAL_VIRTUAL_WIDTH * (TRACK_X + 0.009f), ACTUAL_VIRTUAL_HEIGHT * (TRACK_Y + 0.16f+ HEIGHT_ADJUST));
		stage.addActor(name);
	}

	public void switchButton(PLAYER_TYPE pType) {
		switch (pType) {
		case RINGER:
			name.setText("Ringer Track 1");
			break;
		case APRIL:
			name.setText("April Track 1");
			break;
		case GEO:
			name.setText("Geo Track 1");
			break;
		}
	}

	public void unlock(PLAYER_TYPE pType) {
		switch (pType) {
		case RINGER:

			break;
		case APRIL:
			switchButton(pType);
			subject.notify(Event.EVENT_TRACK1_SELECTED);
			break;
		case GEO:
			switchButton(pType);
			subject.notify(Event.EVENT_TRACK1_SELECTED);
			break;
		}
	}

}
